/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bs.persistencia;

import com.bs.util.Mensagens;
import com.bs.util.TelaErro;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.FlushModeType;
import javax.persistence.TemporalType;

/**
 *
 * @author Bone
 */
public class Query implements javax.persistence.Query {

    private org.hibernate.Query query;
    private FlushModeType fmt;

    public Query(org.hibernate.Query query) {
        this.query = query;
    }

    @Override
    public List getResultList() {
        try {
            return query.list();
        } catch (Exception ex) {
            TelaErro.exibeErro(ex);
        }
        return null;
    }

    @Override
    public Object getSingleResult() {
        try {
            return query.uniqueResult();
        } catch (Exception ex) {
            TelaErro.exibeErro(ex);
        }
        return null;
    }

    @Override
    public int executeUpdate() {
        try {
            return query.executeUpdate();
        } catch (Exception ex) {
            TelaErro.exibeErro(ex);
        }
        return -1;
    }

    @Override
    public Query setMaxResults(int i) {
        query.setMaxResults(i);
        return this;
    }

    @Override
    public Query setFirstResult(int i) {
        try {
            query.setFirstResult(i);
        } catch (Exception ex) {
            TelaErro.exibeErro(ex);
        }
        return this;
    }

    @Override
    public Query setHint(String string, Object o) {
        return this;
    }

    @Override
    public Query setParameter(String string, Object o) {
        query.setParameter(string, o);
        return this;
    }

    @Override
    public Query setParameter(String string, Date date, TemporalType tt) {
        query.setParameter(string, date);
        return this;
    }

    @Override
    public Query setParameter(String string, Calendar clndr, TemporalType tt) {
        query.setParameter(string, clndr);
        return this;
    }

    @Override
    public Query setParameter(int i, Object o) {
        query.setParameter(i, o);
        return this;
    }

    @Override
    public Query setParameter(int i, Date date, TemporalType tt) {
        query.setParameter(i, date);
        return this;
    }

    @Override
    public Query setParameter(int i, Calendar clndr, TemporalType tt) {
        query.setParameter(i, clndr);
        return this;
    }

    @Override
    public Query setFlushMode(FlushModeType fmt) {
        this.fmt = fmt;
        return this;
    }
}
